# -*- coding: utf-8 -*-
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
# Licensed under the MIT License (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
#     http://opensource.org/licenses/MIT
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language governing permissions and
# limitations under the License.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.

# Generated by Django 2.2.17 on 2020-11-27 02:50

from django.db import migrations, models
import django.db.models.deletion
import jsonfield.fields
import paasng.utils.models
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('engine', '0001_initial'),
        ('applications', '0002_auto_20201127_1050'),
    ]

    operations = [
        migrations.CreateModel(
            name='CIResourceAppEnvRelation',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('region', models.CharField(help_text='部署区域', max_length=32)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('credentials', jsonfield.fields.JSONField(default={})),
                ('enabled', models.BooleanField(default=True, verbose_name='是否启用')),
                ('backend', models.CharField(max_length=32, verbose_name='CI引擎')),
                (
                    'env',
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='ci_resources',
                        to='applications.ApplicationEnvironment',
                    ),
                ),
            ],
            options={
                'get_latest_by': 'created',
            },
        ),
        migrations.CreateModel(
            name='CIResourceAtom',
            fields=[
                ('region', models.CharField(help_text='部署区域', max_length=32)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                (
                    'id',
                    models.CharField(
                        db_index=True,
                        max_length=64,
                        primary_key=True,
                        serialize=False,
                        unique=True,
                        verbose_name='原子 ID',
                    ),
                ),
                ('name', models.CharField(max_length=32, verbose_name='原子名称')),
                ('enabled', models.BooleanField(default=True, verbose_name='是否启用')),
                ('backend', models.CharField(max_length=32, verbose_name='CI引擎')),
                (
                    'env',
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='ci_resource_atoms',
                        to='applications.ApplicationEnvironment',
                    ),
                ),
                (
                    'resource',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='related_atoms',
                        to='ci.CIResourceAppEnvRelation',
                    ),
                ),
            ],
            options={
                'unique_together': {('env', 'name', 'backend')},
            },
        ),
        migrations.CreateModel(
            name='CIAtomJob',
            fields=[
                (
                    'id',
                    models.UUIDField(
                        auto_created=True,
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                        unique=True,
                        verbose_name='UUID',
                    ),
                ),
                ('region', models.CharField(help_text='部署区域', max_length=32)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('operator', paasng.utils.models.BkUserField(blank=True, db_index=True, max_length=64, null=True)),
                ('source_type', models.CharField(max_length=16, null=True, verbose_name='源码托管类型')),
                ('source_location', models.CharField(max_length=2048, verbose_name='代码地址')),
                ('source_version_type', models.CharField(max_length=64, verbose_name='代码版本类型')),
                ('source_version_name', models.CharField(max_length=64, verbose_name='代码版本名称')),
                ('source_revision', models.CharField(max_length=128, null=True, verbose_name='版本号')),
                ('source_comment', models.TextField(verbose_name='版本说明')),
                (
                    'status',
                    models.CharField(
                        choices=[('successful', 'successful'), ('failed', 'failed'), ('pending', 'pending')],
                        default='pending',
                        max_length=16,
                        verbose_name='执行状态',
                    ),
                ),
                ('backend', models.CharField(max_length=32, verbose_name='CI引擎')),
                ('build_id', models.CharField(max_length=128, verbose_name='构建ID')),
                ('output', jsonfield.fields.JSONField(default={})),
                (
                    'atom',
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='related_jobs',
                        to='ci.CIResourceAtom',
                    ),
                ),
                (
                    'deployment',
                    models.OneToOneField(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='ci_job',
                        to='engine.Deployment',
                    ),
                ),
                (
                    'env',
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name='ci_atom_jobs',
                        to='applications.ApplicationEnvironment',
                    ),
                ),
            ],
            options={
                'abstract': False,
            },
        ),
    ]
